//
//  JMFormBaseCell.m
//  SYPerfectDemo
//
//  Created by Lssyyy on 2019/7/31.
//  Copyright © 2019年 Lssyyy. All rights reserved.
//

#import "JMFormBaseCell.h"

@implementation JMFormBaseCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configure];
    }
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self configure];
}

- (void)configure
{
}

- (void)update
{
    self.textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    self.detailTextLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    self.textLabel.textColor  = self.rowDescriptor.isDisabled ? [UIColor grayColor] : [UIColor blackColor];
}

-(void)highlight
{
}

-(void)unhighlight
{
}

-(JMFormBaseViewController *)formViewController
{
    id responder = self;
    while (responder){
        if ([responder isKindOfClass:[JMFormBaseViewController class]]){
            return responder;
        }
        responder = [responder nextResponder];
    }
    return nil;
}

#pragma mark - Navigation Between Fields

//-(UIView *)inputAccessoryView
//{
//    UIView * inputAccessoryView = [self.formViewController inputAccessoryViewForRowDescriptor:self.rowDescriptor];
//    if (inputAccessoryView){
//        return inputAccessoryView;
//    }
//    return [super inputAccessoryView];
//}

-(BOOL)formDescriptorCellCanBecomeFirstResponder
{
    return NO;
}

#pragma mark -

-(BOOL)becomeFirstResponder
{
    BOOL result = [super becomeFirstResponder];
    if (result){
        [self.formViewController beginEditing:self.rowDescriptor];
    }
    return result;
}

-(BOOL)resignFirstResponder
{
    BOOL result = [super resignFirstResponder];
    if (result){
        [self.formViewController endEditing:self.rowDescriptor];
    }
    return result;
}

@end
